package ch07;

class _18_PolyArgumentTest2 {
	public static void main(String args[]) {
		Buyer18 b = new Buyer18();
		Tv17 tv = new Tv17();
		Computer com = new Computer();
		Audio audio = new Audio();
		b.buy(tv);
		b.buy(com);
		b.buy(audio);
		b.summary();
	}
}

class Audio extends Product {
	Audio() {
		super(50);
	}

	public String toString() {
		return "Audio";
	}
}

class Buyer18 {
	int money = 1000;
	int bonusPoint = 0;
	Product[] item = new Product[10];
	int i = 0;

	void buy(Product p) {
		if (money < p.price) {
			System.out.println("money is scarce.");
			return;
		}

		money -= p.price;
		bonusPoint += p.bonusPoint;
		item[i++] = p;
		System.out.println("buy " + p);
	}

	void summary() {
		int sum = 0;
		String itemList = "";

		for (int i = 0; i < item.length; i++) {
			if (item[i] == null) break;
			sum += item[i].price;
			itemList += item[i] + " ";
		}

		System.out.println("purchase money: " + sum);
		System.out.println("item purchased: " + itemList);
	}
}
/*
buy Tv
buy Computer
buy Audio
purchase money: 350
item purchased: Tv Computer Audio 
*/
